/*
 * @Author: linweizeng 2630208719@qq.com
 * @Date: 2024-12-04 17:02:43
 * @LastEditors: linweizeng 2630208719@qq.com
 * @LastEditTime: 2025-04-10 11:05:44
 * @FilePath: \honor-of-kings\src\router\index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AEibi
 */
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import home from '@/views/home/index.vue';
import index404 from '@/views/404/index.vue';
import bilibili from '@/views/bilibili/index.vue'
import indexChild from '@/views/bilibili/indexChild.vue'

const routes = [
  {
    path: '/',
    component: bilibili,
    meta: {
      title: 'bilibili v1.0.041001' // 页面标题
    }
  },
  {
    path: '/indexChild',
    name: '详情',
    component: indexChild,
    meta: {
      title: '详情' // 页面标题
    }
  },
  {
    path: '/404',
    name: '404',
    component: index404
  },
  // 404 通配符路由，处理未找到的路径
  {
    path: '/:pathMatch(.*)*',
    name: 'not-found',
    component: index404
  },
  // 可以添加更多的路由规则
];

// 根据需求选择路由模式
const historyMode = import.meta.env.VUE_ROUTER_MODE === 'history' ? createWebHistory : createWebHashHistory;
const router = createRouter({
  history: historyMode(),
  routes,
});

// 路由守卫
router.beforeEach((to, from, next) => {
  // Update page title
  if (to.meta && typeof to.meta.title === 'string') {
    document.title = to.meta.title;
  }
  next();
});

export default router;